<?php
/**
 * Created by PhpStorm.
 * User: Adminstratot
 * Date: 2019/4/24
 * Time: 8:48
 */

namespace app\api\model;


class Banner extends BaseModel
{
    //php think optimize:schema 生成数据库字段缓存
    //protected $table='category';  选择其它表
    protected $hidden = ['update_time','delete_time'];
    public function items(){
        return $this->hasMany('BannerItem','banner_id','id');
    }
    public static function getBannerByID($id){
        /*$result=Db::query('select * from banner_item where banner_id=?',[$id]);
        return $result;*/
        /*$result=Db::table('banner_item')
            ->fetchSql()
            ->where('banner_id','=',$id)
            ->select();*/
        //where('字段名','表达式','查询条件');
        //表达式、数组法、闭包
        /*$result=Db::table('banner_item')
            ->where(function ($query) use ($id){
                $query->where('banner_id','=',$id);
            })
            ->select();*/
        $banner = self::with(['items','items.img'])->find($id);
        return $banner;
    }
}